#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

class Animal {
private:
    std::string name;
    std::string species;
    int age;

public:
    Animal(const std::string& n, const std::string& s, int a) 
        : name(n), species(s), age(a) {}

    std::string getName() const { return name; }
    std::string getSpecies() const { return species; }
    int getAge() const { return age; }

    void display() const {
        std::cout << "Name: " << name << ", Species: " << species << ", Age: " << age << std::endl;
    }
};

class Zoo {
private:
    std::vector<Animal> animals;

public:
    void addAnimal(const Animal& animal) {
        animals.push_back(animal);
        std::cout << "Animal added successfully!" << std::endl;
    }

    void displayAllAnimals() const {
        if (animals.empty()) {
            std::cout << "No animals in the zoo!" << std::endl;
            return;
        }
        std::cout << "\nAll Animals in the Zoo:" << std::endl;
        for (const auto& animal : animals) {
            animal.display();
        }
    }

    void findAnimal(const std::string& name) const {
        auto it = std::find_if(animals.begin(), animals.end(),
            [&name](const Animal& animal) { return animal.getName() == name; });

        if (it != animals.end()) {
            std::cout << "\nAnimal found:" << std::endl;
            it->display();
        } else {
            std::cout << "Animal not found!" << std::endl;
        }
    }

    void deleteAnimal(const std::string& name) {
        auto it = std::find_if(animals.begin(), animals.end(),
            [&name](const Animal& animal) { return animal.getName() == name; });

        if (it != animals.end()) {
            animals.erase(it);
            std::cout << "Animal deleted successfully!" << std::endl;
        } else {
            std::cout << "Animal not found!" << std::endl;
        }
    }
};

void displayMenu() {
    std::cout << "\n=== Zoo Management System ===" << std::endl;
    std::cout << "1. Add Animal" << std::endl;
    std::cout << "2. Display All Animals" << std::endl;
    std::cout << "3. Find Animal" << std::endl;
    std::cout << "4. Delete Animal" << std::endl;
    std::cout << "5. Exit" << std::endl;
    std::cout << "Enter your choice (1-5): ";
}

int main() {
    Zoo zoo;
    int choice;
    std::string name, species;
    int age;

    while (true) {
        displayMenu();
        std::cin >> choice;
        std::cin.ignore(); // Clear the newline character

        switch (choice) {
            case 1: {
                std::cout << "Enter animal name: ";
                std::getline(std::cin, name);
                std::cout << "Enter animal species: ";
                std::getline(std::cin, species);
                std::cout << "Enter animal age: ";
                std::cin >> age;
                zoo.addAnimal(Animal(name, species, age));
                break;
            }
            case 2:
                zoo.displayAllAnimals();
                break;
            case 3: {
                std::cout << "Enter animal name to find: ";
                std::getline(std::cin, name);
                zoo.findAnimal(name);
                break;
            }
            case 4: {
                std::cout << "Enter animal name to delete: ";
                std::getline(std::cin, name);
                zoo.deleteAnimal(name);
                break;
            }
            case 5:
                std::cout << "Thank you for using Zoo Management System!" << std::endl;
                return 0;
            default:
                std::cout << "Invalid choice! Please try again." << std::endl;
        }
    }

    return 0;
} 